<h2>Forgot Password</h2>
<cfset showform = 1>

<cfif isdefined('form.forgot_username')>

	<!---form cleaner--->
    <cfinvoke component="cfcs.common.cleaner" method="cleanforminput" fields="#form#" returnvariable="cleanfields" /> 
    <cfloop collection="#cleanfields#" item="var">
        <cfset "form.#var#" = #evaluate('cleanfields.' & var)#>
        <cfset "#var#" = #evaluate('cleanfields.' & var)#>
    </cfloop>
	
    <cfquery name = "qgetmember" datasource="#request.dsn#" maxrows="1">
    SELECT email,pword FROM core_accounts
    WHERE username = <cfqueryparam value="#form.forgot_username#" cfsqltype="cf_sql_varchar"> 
    OR email = <cfqueryparam value="#form.forgot_username#" cfsqltype="cf_sql_varchar">
    </cfquery>
    
    <cfif qgetmember.recordcount GT 0>
	<cftry>
    	<cfinvoke component="cfcs.common.encryption" method="decryptstring" encstring="#qgetmember.pword#" returnvariable="userpass">
    <cfcatch type="any">
    	<cfset userpass = 'Please contact support to reset your password.'>
    </cfcatch>
    </cftry>
        
        <cfmail from="#request.site_email#" to="#qgetmember.email#" subject="Your #request.site_name# Password">
        Your password is #userpass#       
    </cfmail>
        
        <div style="color: #009900; font-weight: bold;">Your password has been emailed to the email address on your account: <cfoutput>#qgetmember.email#</cfoutput>.</div>
		<cfset showform = 0>
    <cfelse>
    	<div style="color: #FF0000; font-weight: bold;">Invalid username or email.</div>
    </cfif>
    
</cfif>

<cfif showform IS 1>
<div>
  <form name="form1" method="post" action="index.cfm?c=affiliates_login&a=forgotpassword">
    <p>Enter your email address in the box below and we will email you your password:<br>
      <br>
    </p>
    <p>Email: 
      <input type="text" name="forgot_username" id="forgot_username">
      <input type="submit" name="button" id="buttons" value="Send Password">
    </p>
  </form>
</div>
</cfif>
<a href = "index.cfm?c=account_login">Go to login</a>  